package icu.lookyousmileface.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author starrysky
 * @title: MyMataHandler
 * @projectName mybaits_plus_final
 * @description: Meta处理器，当对应pojo的字段上设置@TableField值时，
 * 触发了inster/update时间都会更新createTime或者updateTime两个字段
 * @date 2021/1/3123:28
 */

@Slf4j
@Component
public class MyMataHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
      log.info("有数据开始插入....开始更新创建时间戳");
      this.setFieldValByName("createTime",new Date(),metaObject);
      this.setFieldValByName("updateTime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("有数据被操作...开始更新最新的时间戳");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
